// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSegmentAttributesImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "SQLPartitionValue.h"
#include "../visitor/SQLASTVisitor.h"
#include "SQLExpr.h"
#include "../../utils/listTran.h"

SQLPartitionValue::SQLPartitionValue(SQLPartitionValue_Operator operator_)
{
  super();
  this->operator_ = operator_;
  items=std::make_shared<std::list<SQLExpr_ptr >> ();
}

SQLExpr_list_ptr SQLPartitionValue::getItems()
{
  return items;
}

void SQLPartitionValue::addItem(SQLExpr_ptr item)
{
  if (item != nullptr)
  {
    item->setParent(SharedObject(SQLPartitionValue));
  }
  this->items->push_back(item);
}

SQLPartitionValue_Operator SQLPartitionValue::getOperator()
{
  return operator_;
}

// @Override
void SQLPartitionValue::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLPartitionValue)))
  {
    SQLObject_list_ptr  tmp = ListTran::tran_class<SQLExpr , SQLObject>(getItems());
    acceptChild(visitor, tmp);
  }
  visitor->endVisit(SharedObject(SQLPartitionValue));
}

SQLObject_ptr  SQLPartitionValue::clone()
{
    SQLObject_ptr clone_tmp = SQLPartitionValue_ptr(new SQLPartitionValue(operator_));
    SQLPartitionValue_ptr x = std::dynamic_pointer_cast<SQLPartitionValue>(clone_tmp);
  // SQLPartitionValue *x = new SQLPartitionValue(operator_);

  for (SQLExpr_ptr item : *items)
  {
    SQLExpr_ptr item2 = std::dynamic_pointer_cast<SQLExpr>(item->clone());
    item2->setParent(x);
    x->items->push_back(item2);
  }

  return x;
}
